﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KendoMvcUI.Common;
using KendoMvcUI.Core;
using System.Web.Mvc;

namespace KendoMvcUI.UI
{
    public class ListView:KendoUIBase
    {
        public ListView(KendoUIControlSettings settings,ViewContext context,IViewDataContainer container)
            :base(settings,context,container)
        { }
        public override string RenderHtml()
        {
            return "<div id=\"{0}\"></div>".Formator(Settings.Id);
        }
    }
    public class ListViewSettings : KendoBindingBase
    {
        public ListViewSettings()
            : base("kendoListView")
        { }
        /// <summary>
        /// If set to false the widget will not bind to the data source during initialization
        /// </summary>
        public bool? AutoBind { get; set; }
        /// <summary>
        /// template id
        /// </summary>
        [PropertySetting(IsIngoreForJavaScript = true)]
        public string EditTemplateId { get; set; }
        public string EditTemplate { get; set; }
        /// <summary>
        /// Indicates whether keyboard navigation is enabled/disabled.
        /// </summary>
        public bool? Navigatable { get; set; }
        /// <summary>
        /// Indicates whether selection is enabled/disabled
        /// default:false
        /// </summary>
        public bool? Selectable { get; set; }
        [PropertySetting(IsIngoreForJavaScript = true)]
        public bool? Multiple { get; set; }
        public string Template { get; set; }
        [PropertySetting(IsIngoreForJavaScript = true)]
        public string TemplateId { get; set; }
        public string AltTemplate { get; set; }
        [PropertySetting(IsIngoreForJavaScript = true)]
        public string AltTemplateId { get; set; }
        #region 事件
        public string On_Cancel { get; set; }
        public string On_Change { get; set; }
        public string On_DataBound { get; set; }
        public string On_DataBinding { get; set; }
        public string On_Edit { get; set; }
        public string On_Remove { get; set; }
        public string On_Save { get; set; }
        #endregion
        public override string ToJsSettings()
        {
            string jsScript = base.ToJsSettings();
            string templateId = "{0}:kendo.template($({1}).html())";
            if (!string.IsNullOrWhiteSpace(EditTemplateId))
            {
                if (!jsScript.EndsWith(","))
                    jsScript += ",";
                jsScript += string.Format(templateId, "editTemplate", EditTemplateId);
            }
            if (Multiple.HasValue)
            {
                if (!jsScript.EndsWith(","))
                    jsScript += ",";
                if (Multiple.Value == false)
                    jsScript += "selectable:\"single\"";
                else
                    jsScript += "selectable:\"multiple\"";
            }
            if (!string.IsNullOrWhiteSpace(TemplateId))
            {
                if (!jsScript.EndsWith(","))
                    jsScript += ",";
                jsScript += string.Format(templateId, "template", TemplateId);
            }
            if (!string.IsNullOrWhiteSpace(AltTemplateId))
            {
                if (!jsScript.EndsWith(","))
                    jsScript += ",";
                jsScript += string.Format(templateId, "altTemplate", AltTemplateId);
            }
            return jsScript.TrimEnd(',');
        }
    }
}
